package com.StarStudio.DAO;


import com.ruoyi.common.core.Entity.Orders;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
@SuppressWarnings("all")
public interface OrdersDAO {


    List<Orders> findOrdersList(Orders orders);
    List<Orders> findOrdersListByNormalStore(@Param("orders") Orders orders, @Param("LoginUserId") long LoginUserId);

    List<Orders> findGoodsOrdersList(Orders orders);

    List<Orders> findGoodsOrdersListByNormalStore(@Param("orders") Orders orders, @Param("LoginUserId") long LoginUserId);

    List<Orders> findCouponsOrdersList(Orders orders);

    @Select("select count(0) from orders where del_flag = false")
    long findAllRecordForAdmin();

    @Select("select count(0) from orders where store_id = #{store_id} and del_flag = false")
    long findAllRecordForNormalStore(long store_id);

    @Insert("insert into orders values (null,#{order_user_id},#{store_id},#{goods_id},#{coupons_id},#{number},#{order_status},#{consignee_name}," +
            "#{consignee_phone},#{consignee_address},#{deliver_type},#{order_time},#{deliver_time},#{del_flag})")
    @Options(useGeneratedKeys = true,keyProperty = "order_id",keyColumn = "order_id")
    void orderAdd(Orders orders);

    @Update("update orders set order_user_id = #{order_user_id},store_id = #{store_id},goods_id = #{goods_id},coupons_id = #{coupons_id}, number = #{number}," +
            "order_status = #{order_status},consignee_name = #{consignee_name},consignee_phone = #{consignee_phone},consignee_address = #{consignee_address}," +
            "deliver_type = #{deliver_type},order_time = #{order_time},deliver_time = #{deliver_time},del_flag = #{del_flag} where order_id = #{order_id}")
    void updateOrder(Orders orders);

    @Select("select * from orders where order_id = #{order_id}")
    Orders findByOrder_id(long order_id);

    @Select("select count(0) from orders where date_format(order_time,'%Y-%m-%d') = #{today}")
    int New_order_number_today(String today);

    @Select("select * from orders where store_id = #{store_id} and date_format(order_time,'%Y-%m-%d') = #{today}")
    List<Orders> findOrdersByStoreIdandTime(@Param("store_id") long store_id,@Param("today") String today);

    @Select("select * from orders where store_id = #{store_id}")
    List<Orders> findOrdersByStoreId(long store_id);

    @Select("select distinct order_user_id from orders where store_id = #{store_id} and date_format(order_time,'%Y-%m-%d') = #{today}")
    List<Long> findPurchaseUserToday(@Param("store_id") long store_id,@Param("today") String today);

    @Select("select distinct order_user_id from orders where store_id = #{store_id}")
    List<Long> findPurchaseUserTotal(long store_id);

    @Select("select count(0) from orders where goods_id > 0 and del_flag = false")
    long findAllGoodsRecordNumber();

    @Select("select count(0) from orders where coupons_id > 0 and del_flag = false")
    long findAllCouponsRecordNumber();
}
